package cn.shop.cloud.mapper;


import cn.shop.cloud.domain.Good;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * @program: work
 * @ClassName GoodMapper
 * @description:
 * @author: 李尧坤
 * @create: 2025−01-08 20:56
 * @Version 1.0
 **/

@Mapper
public interface GoodMapper {
    // 相当于select * from t_goods where id in(1,2,3)

    @SelectProvider(type =GoodMapperSQLProvider.class,method = "queryByIds")
    public List<Good> queryByIds(@Param("ids") List<Long> ids);

    class GoodMapperSQLProvider{
        public  String queryByIds(@Param("ids") List<Long> ids){

            StringBuilder sb = new StringBuilder();
            sb.append("SELECT * FROM t_goods ");
            if(ids!=null && ids.size()>0){
                sb.append(" where id in (");
                for (int i = 0; i < ids.size(); i++) {
                    if(i!=0){
                        sb.append(",");
                    }
                    sb.append(ids.get(i));
                }
                sb.append(")");
            }

            return sb.toString();

        }

    }
}